package com.api.oa.controller;


import com.api.oa.model.entity.YQFaceAttend;
import com.api.oa.services.YQFaceAttendService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yq/yQFaceAttend")
public class YQFaceAttendController extends BaseController {

    @Autowired
    private YQFaceAttendService iYQFaceAttendService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public MyResult Add(@RequestBody YQFaceAttend entity) {
        try {
            return iYQFaceAttendService.add(entity) == 1 ? success(entity) : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/remove/{id}", method = RequestMethod.POST)
    public MyResult remove(@PathVariable Long id) {
        try {
            iYQFaceAttendService.remove(id);
            return success("删除成功!");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/attend/{id}", method = RequestMethod.GET)
    public MyResult findWeekAttend(@PathVariable Long id) {
        try {

            return success(iYQFaceAttendService.findWeekAttend(id));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public MyResult update(@RequestBody YQFaceAttend entity) {
        try {
            return iYQFaceAttendService.update(entity) == 1 ? success("操作成功") : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MyResult list(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "20") Integer pageSize, @RequestParam(required = false) String insCode,
                         @RequestParam(required = false) String status, @RequestParam(required = false) String type, @RequestParam(required = false) String role) {
        try {
            return success(iYQFaceAttendService.list(insCode, status, type, role, pageIndex, pageSize));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
    public MyResult one(@PathVariable Long id) {
        try {
            return success(id == null ? null : iYQFaceAttendService.one(id));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


}
